import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'
import { SupportService } from './support.service'
import { CreateSupportDto } from './dto/create-support.dto'
import { AuthJWT } from 'src/decorator/auth.decorator'
import { GetUserInfo } from 'src/decorator/getUserInfo.decotator'
import { User } from '@prisma/client'
import { Throttle } from '@nestjs/throttler'

@Controller('support')
export class SupportController {
   constructor(private readonly supportService: SupportService) {}

   @Throttle({ default: { limit: 1, ttl: 1000 } })
   @AuthJWT()
   @Post()
   create(@Body() createSupportDto: CreateSupportDto, @GetUserInfo() user: User) {
      return this.supportService.create(createSupportDto, +user.id)
   }

   @AuthJWT()
   @Get(':id')
   find(id: number) {
      return this.supportService.findAll(id)
   }

   @AuthJWT()
   @Get('/findOne/:articleId')
   findOne(@Param('articleId') articleId: number, @GetUserInfo() user: User) {
      return this.supportService.findUserOne(articleId, +user.id)
   }

   @Get('/count/:articelId')
   countNum(@Param('articelId') articelId: number) {
      return this.supportService.countNum(+articelId)
   }

   @AuthJWT()
   @Delete(':id')
   @Throttle({ default: { limit: 1, ttl: 1000 } })
   remove(@Param('id') id: number) {
      return this.supportService.remove(+id)
   }
}
